<script>
	var url;
	$(document).ready(function(){
	
		approve = function (value){
			//if(confirm("Apakah yakin akan menghapus data '" + row.nama_krs + "'?")){
				var response = '';
				$.ajax({ type: "GET",
					 url: base_url+'krs_approve/approve/' + value,
					 async: false,
					 success : function(response){
						var response = eval('('+response+')');
						if (response.success){
							$.messager.show({
								title: 'Success',
								msg: 'Data Berhasil Disetujui'
							});
							$('#dg').datagrid('reload');
						} else {
							$.messager.show({
								title: 'Error',
								msg: response.msg
							});
						}
					 }
				});
			//}
		}
		//end deleteData 
		
		
		actionbutton = function(value, row, index){
			var col;
			col = '<a href="#" onclick="approve(\''+row.id_krs+'\');" class="easyui-linkbutton" plain="false">Approve</a>';
			return col;
		}
		
		// load grid
		$(function(){
			$('#dg').datagrid({url:"<?=base_url()?>krs_approve/grid"});	
			//$('#dg').datagrid('enableFilter'); 			
		});	
		
		
		// onchange
		$('#s_kd_fakultas').change(function(){
			$('#s_kd_prodi').load(base_url+'prosedur/getProdibyFakultas/'+$('#s_kd_fakultas').val());
		});
		
		// filter
		filter = function(){
			$('#dg').datagrid('load',{
				kd_fakultas : $('#s_kd_fakultas').val(),
				kd_prodi : $('#s_kd_prodi').val(),
				tahun : $('#s_tahun').val()
			});
			//$('#dg').datagrid('enableFilter');
		}
		
		// detail grid
		$('#dg').datagrid({
			view: detailview,
			detailFormatter:function(index,row){
				return '<div style="padding:2px"><table id="ddv-' + index + '"></table></div>';
			},
			onExpandRow: function(index,row){
				$('#ddv-'+index).datagrid({
					url:base_url+'krs_approve/grid_detail/'+row.id_krs,
					fitColumns:false,
					singleSelect:true,
					rownumbers:true,
					loadMsg:'',
					height:'auto',
					columns:[[
						{field:'kd_matakuliah',title:'Kode MK',width:150},
						{field:'nama_matakuliah',title:'Mata Kuliah',width:250},
						{field:'sks',title:'SKS',width:100,align:'center'},
						{field:'semester',title:'Semester',width:100,align:'center'}
					]],
					onResize:function(){
						$('#dg').datagrid('fixDetailRowHeight',index);
					},
					onLoadSuccess:function(){
						setTimeout(function(){
							$('#dg').datagrid('fixDetailRowHeight',index);
						},0);
					}
				});
				$('#dg').datagrid('fixDetailRowHeight',index);
			}
		});
		
	});	
		
</script>

<table id="dg" title="Kelola Data krs " data-options="
			rownumbers:true,
			singleSelect:true,
			autoRowHeight:false,
			pagination:true,
			pageSize:30,
			fit:true,
			cache:false,
			toolbar:'#toolbar'
			">
<!--
<table id="dg" class="easyui-treegrid"  data-options="
			rownumbers:true,
			singleSelect:true,
			collapsible:true,
			autoRowHeight:false,
			pagination:true,
			pageSize:30,
			fit:true,
			toolbar:'#toolbar',
			view:groupview,
			groupField:'nim',
			">			
-->						
	<thead>
		<tr>
			<!--<th field="tahun_penerimaan" sortable="true" width="80">Tahun Penerimaan</th> -->
			<th field="id_krs" sortable="true" hidden="true" width="100">id_krs</th>
			<th field="nim" sortable="true" width="100">NIM</th>
			<th field="nama" sortable="true" width="100">Nama</th>
			<th field="nama_dosen" sortable="true" width="150">Dosen Wali</th>
			<th field="ips" sortable="true" width="75">IPS</th>
			<th field="semester" sortable="true" width="75">Semester</th>
			<th field="total_mk" sortable="true" width="75">T. MK</th>
			<th field="total_sks" sortable="true" width="75">T. SKS</th>
			
			<th field="aksi" sortable="true" formatter="actionbutton" width="100">Aksi</th>
		</tr>
	</thead>
</table>
<div id="toolbar" style="padding:5px;height:auto">
	<div class="fsearch">
		<table width="900" border="0">
		  <tr>
			<td>Fakultas</td>
			<td>: 
				<select id="s_kd_fakultas" name="s_kd_fakultas" style="width:290px;">
					<?=$this->mdl_prosedur->OptionFakultas();?>
				</select>
			</td>
			<td>&nbsp;</td>
			<td>Tahun Ajaran</td>
			<td>: 
				<select id="s_tahun" name="s_tahun" style="width:220px;" disabled="disabled">
					<?=$this->mdl_prosedur->OptionTahunAjaran(array('value' => $tahun));?>
				</select>
			</td>
		  </tr>
		  <tr>
			<td>Program Studi</td>
			<td>: 
				<select id="s_kd_prodi" name="s_kd_prodi" style="width:290px;">
					<?=$this->mdl_prosedur->OptionProdi();?>
				</select>
			</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;&nbsp;<a href="#" onclick="filter()" class="easyui-linkbutton" iconCls="icon-search">Filter</a></td>
		  </tr>
		</table>
	</div>
</div>
